package com.IO.practice;

import java.io.*;
import java.util.ArrayList;
import java.util.TreeMap;

public class D04 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("D:\\TestFile\\test\\a.txt"));
        ArrayList<String> lineList = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            lineList.add(line);
        }
        br.close();
        TreeMap<Integer,String> tm = new TreeMap<>();
        lineList.forEach(e->{
            tm.put(
                    Integer.parseInt(e.substring(0,1)),
                    e.substring(2)
            );
        });
        BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\TestFile\\test\\b.txt"));
        tm.forEach((k,v)->{
            try {
                bw.write(v);
                bw.newLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
        bw.close();
    }

}
